package com.cn.kabalifemerchants.config;

import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;

/**
 * Created by 晓林 on 2019/11/18.
 * function:
 */
public class RefreshHelper {

    public static void initRefreshLayout(SmartRefreshLayout refreshLayout, final CustomRefreshListener customRefreshListener) {
//        refreshLayout.setEnableLoadMore(true);
        refreshLayout.setEnableAutoLoadMore(false);  //滚动列表自动加载更多
        refreshLayout.setDisableContentWhenRefresh(true); //刷新的时候禁止操作列表
        refreshLayout.setDisableContentWhenLoading(true);//是否在加载的时候禁止列表的操作
        refreshLayout.setEnableScrollContentWhenLoaded(true);//是否在加载完成时滚动列表显示新的内容
        refreshLayout.setEnableFooterTranslationContent(true);//是否上拉Footer的时候向上平移列表或者内容
        refreshLayout.setOnRefreshListener(new OnRefreshListener() {
            @Override
            public void onRefresh(RefreshLayout refreshLayout) {
                customRefreshListener._onRefresh(refreshLayout);
            }
        });
        refreshLayout.setOnLoadMoreListener(new OnLoadMoreListener() {
            @Override
            public void onLoadMore(RefreshLayout refreshLayout) {
                customRefreshListener._onLoadMore(refreshLayout);
            }
        });
    }

    public static void finishRefresh(SmartRefreshLayout refreshLayout, int page) {
        if (null != refreshLayout) {
            if (page == 1) {
                refreshLayout.finishRefresh();
            } else {
                refreshLayout.finishLoadMore();
            }
        }
    }
}
